<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>添订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 搜索框区域 -->
      <el-row :gutter="20">
        <el-col :span="7">
          <el-input placeholder="请输入内容" clearable v-model="queryInfo.query">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="orderList" border stripe style="width: 100%">
        <el-table-column type="index" width="50" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="180">
          <template slot-scope="scope">
            <!-- {{scope.row}} -->
            <el-tag type="success" v-if="scope.row.pay_status==='1'">已付款</el-tag>
            <el-tag type="danger" v-if="scope.row.pay_status==='0'">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="180"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="180">
          <template slot-scope="scope">{{scope.row.create_time | dateFomat}}</template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <el-button
            type="primary"
            icon="el-icon-edit"
            size="small"
            @click="editAdressDialogVisible = true"
          ></el-button>
          <el-button type="success" icon="el-icon-location" size="small" @click="showProBoxDialog"></el-button>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10,20, 30, 40]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editAdressDialogVisible"
      width="50%"
      @close="editAdressClosed"
    >
      <!-- 修改地址表单区域 -->
      <el-form
        :model="editAdressForm"
        :rules="editAdressrules"
        ref="editAdressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="adress1">
          <!-- <el-input v-model="editAdressForm.adress1"></el-input> -->
          <el-cascader v-model="editAdressForm.adress1" :options="cityData" :props="props"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="adress2">
          <el-input v-model="editAdressForm.adress2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editAdressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editAdressDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 展示物流进度对话框 -->
    <el-dialog title="物流进度" :visible.sync="showProBoxVisible" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in progressBoxInfo"
          :key="index"
          :timestamp="item.time"
        >{{item.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      // 查询订单列表参数
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
        user_id: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '',
        order_fapiao_company: '',
        order_fapiao_content: '',
        consignee_addr: ''
      },
      // 订单列表
      orderList: [],
      // 订单总数目
      total: 0,
      // 修改订单地址对话框切换显示
      editAdressDialogVisible: false,
      // 编辑地址表单
      editAdressForm: {
        adress1: '',
        adress2: ''
      },
      // 编辑地址表单规则
      editAdressrules: {
        adress1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        adress2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      // 城市信息
      cityData: cityData,
      // 级联选择器配置
      props: {
        expandTrigger: 'hover',
        value: 'value',
        label: 'label',
        children: 'children'
      },
      // 展示物流进度对话框切换显示
      showProBoxVisible: false,
      // 物流信息
      progressBoxInfo: []
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    // 获取订单列表
    async getOrdersList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败！')
      }
      this.$message.success('获取订单列表成功！')
      this.total = res.data.total
      this.orderList = res.data.goods
      // console.log(res)
    },
    // 页面大小发生改变
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getOrdersList()
    },
    // 当前页面发生改变
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.getOrdersList()
    },
    // 修改地址对话框关闭时
    editAdressClosed() {
      this.$refs.editAdressFormRef.resetFields()
    },
    // 点击按钮，显示物流进度对话框
    async showProBoxDialog() {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      this.progressBoxInfo = res.data
      this.showProBoxVisible = true
      // console.log(res.data)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
